package com.atguigu.gmall.order.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.cart.CartFeginClient;
import com.atguigu.gmall.model.order.vo.OrderSubmitVo;
import com.atguigu.gmall.order.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order/auth")
public class OrderRestController {

    @Autowired
    OrderInfoService orderInfoService;

    @Autowired
    CartFeginClient cartFeginClient;



    ///submitOrder?tradeNo=ATGUIGU_1693828507946_3
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestParam String tradeNo, @RequestBody OrderSubmitVo orderSubmitVo) {
        Long orderId = orderInfoService.submitOrder(tradeNo,orderSubmitVo);
        //提交订单后要把购物车里面选中的商品删除
        cartFeginClient.deleteChecked();
        //这里必须toString 因为雪花算法生成的id太大了，如果是long前端会自动改变数值
        return Result.ok(orderId.toString());
    }


}
